package com.briup.cms.web.controller;


import com.briup.cms.aop.Logging;
import com.briup.cms.bean.BaseLog;

import com.briup.cms.exception.CustomerException;

import com.briup.cms.service.IBaseLogService;
import com.briup.cms.utils.*;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/auth/log")
@Api(tags = "日志相关接口")
public class BaseLogController {

    @Autowired
    private IBaseLogService baseLogService;
    @ApiOperation("分页查询日志")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页",required = true,paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小",required = true,paramType = "query")
    })
    @GetMapping("/pageQuery")
    public Message pageQuery(int pageNum,int pageSize){

        PageInfo<BaseLog> pageInfo = baseLogService.pageQuery(pageNum, pageSize);
        Map<String, Object> userInfo = UserInfo.getUserInfo();
        String username=(String)userInfo.get("username");
        PageInfo<BaseLog> pageInfo2 = baseLogService.pageQueryByUsername(pageNum, pageSize,username);
        if(JudgeAdmin.Admin)
            return MessageUtil.success(pageInfo2);
        else
            return MessageUtil.success(pageInfo);
    }

    @ApiOperation("添加日志")
    @PostMapping("/AddLogInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="logId",value = "不填",required = false),
            @ApiImplicitParam(name = "logRealname",value = "姓名",required = true,paramType = "query"),
            @ApiImplicitParam(name = "logRequestMethod",value = "请求方法",required = true,paramType = "query"),
            @ApiImplicitParam(name = "logRequestUri",value = "请求uri",required = true,paramType = "query"),
            @ApiImplicitParam(name = "logTime",value = "操作时间",required = true,paramType = "query"),
            @ApiImplicitParam(name = "logUsername",value = "用户名",required = true,paramType = "query")
    })
    public Message AddLogInfo(BaseLog baseLog){
        baseLogService.AddLogInfo(baseLog);
        return MessageUtil.success(baseLog);
    }

    @ApiOperation("根据id删除日志记录")
    @DeleteMapping("/deleteByPrimaryKey")
    @ApiImplicitParam(name = "logId",value = "用户id",required = true,paramType = "query")
    public Message deleteByPrimaryKey(Long logId){
        baseLogService.deleteByPrimaryKey(logId);
        return MessageUtil.success(logId);
    }
    @Logging
    @ApiOperation("根据id查询日志记录")
    @GetMapping("/pageQuery/selectByPrimaryKey")
    public Message selectByPrimaryKey(Long logId){
        BaseLog baseLog=baseLogService.selectByPrimaryKey(logId);
        return MessageUtil.success(baseLog);
    }

    @ApiOperation("修改日志")
    @GetMapping("/updateByPrimaryKey")
    public Message updateByPrimaryKey(BaseLog record){
        baseLogService.updateByPrimaryKey(record);
        return MessageUtil.success();
    }



}
